//
//  UIView+Animate.m
//  CharonTVProject
//
//  Created by karong on 2023/6/19.

#import "UIView+Animate.h"

@implementation UIView (Animate)

- (void)uploadLayout {
    [self setNeedsUpdateConstraints];
    [UIView animateWithDuration:0.2 animations:^{
        [self layoutIfNeeded];
    }];
}

- (void)addScaleAnimtaionWithfromValue:(CGFloat)fromValue toValue:(CGFloat)toValue duration:(NSInteger)duration repeatCount:(NSInteger)repeatCount autoreverses:(BOOL)autoreverses
{
    //放大效果，并回到原位
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    //速度控制函數，控制動画运行的節奏
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.duration = duration;       //执行時間
    animation.repeatCount = repeatCount;      //执行次數
    animation.autoreverses = autoreverses;    //完成動画后會回到执行動画之前的狀態
    animation.fromValue = [NSNumber numberWithFloat:fromValue];   //初始伸缩倍數
    animation.toValue = [NSNumber numberWithFloat:toValue];     //结束伸缩倍數
    [[self layer] addAnimation:animation forKey:nil];
}

///呼吸動效
- (void)addScaleAnimtaion {
    [self addScaleAnimtaionWithfromValue:1 toValue:1.1 duration:0.5 repeatCount:HUGE_VALF autoreverses:YES];
}
@end
